# Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
#
# Licensed under the BSD 3-Clause License (the "License"); you may not use this
# file except in compliance with the License. You may obtain a copy of the
# License at
#
# https://opensource.org/licenses/BSD-3-Clause
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

cc_library(
    name = "binlog",
    srcs = ["init.cc"],
    hdrs = [
        "dry_runner.h",
        "dumper.h",
        "init.h",
        "log_reader.h",
        "log_writer.h",
        "packet_desc.h",
        "tags.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        ":dry_runner",
        ":dumper",
        ":log_reader",
        ":log_writer",
        ":packet_desc",
        "//flare/base:buffer",
        "//flare/base:casting",
        "//flare/base:dependency_registry",
        "//flare/base:expected",
        "//flare/base:future",
        "//flare/base:status",
        "//flare/base/experimental:lazy_eval",
        "//flare/base/experimental:uuid",
        "//flare/base/internal:early_init",
        "//flare/base/net:endpoint",
        "//flare/fiber",
        "//flare/rpc/binlog/text_only:dumper",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_library(
    name = "tags",
    hdrs = ["tags.h"],
    visibility = ["//visibility:public"],
)

cc_library(
    name = "packet_desc",
    srcs = ["packet_desc.cc"],
    hdrs = [
        "packet_desc.h",
    ],
    visibility = ["//visibility:public"],
    deps = [
        "//flare/base:buffer",
        "//flare/base:casting",
        "//flare/base/buffer:zero_copy_stream",
        "//flare/base/experimental:lazy_eval",
        "//flare/base/internal:early_init",
        "@com_google_protobuf//:protobuf",
    ],
)

cc_library(
    name = "dumper",
    srcs = ["dumper.cc"],
    hdrs = ["dumper.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":packet_desc",
        ":tags",
        "//flare/base:buffer",
        "//flare/base:dependency_registry",
        "//flare/base:id_alloc",
        "//flare/base:maybe_owning",
        "//flare/base:never_destroyed",
        "//flare/base:string",
        "//flare/base/experimental:lazy_eval",
        "//flare/base/experimental:uuid",
        "//flare/base/internal:index_alloc",  # ???
        "//flare/base/net:endpoint",
        "//flare/rpc/internal:sampler",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_test(
    name = "dumper_test",
    srcs = ["dumper_test.cc"],
    tags = ["exclusive"],
    deps = [
        ":dumper",
        ":tags",
        ":testing",
        "//flare/base:down_cast",
        "//flare/base:string",
        "//flare/rpc/binlog/text_only:dumper",
        "@com_github_gflags_gflags//:gflags",
        "@com_github_jsoncpp//:jsoncpp",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "log_reader",
    srcs = ["log_reader.cc"],
    hdrs = ["log_reader.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":dry_runner",
        ":tags",
        "//flare/base:string",
        "//flare/base/experimental:uuid",
        "//flare/fiber",
    ],
)

cc_library(
    name = "log_writer",
    srcs = ["log_writer.cc"],
    hdrs = ["log_writer.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":dumper",
        ":tags",
        "//flare/base:chrono",
        "//flare/base/experimental:uuid",
        "//flare/base/internal:dpc",
    ],
)

cc_test(
    name = "log_writer_test",
    srcs = ["log_writer_test.cc"],
    deps = [
        ":log_writer",
        ":testing",
        "//flare/base:down_cast",
        "//flare/base:string",
        "//flare/init:override_flag",
        "//flare/rpc/binlog/text_only:dumper",
        "//flare/testing:main",
        "@com_github_gflags_gflags//:gflags",
        "@com_github_jsoncpp//:jsoncpp",
    ],
)

cc_library(
    name = "testing",
    srcs = ["testing.cc"],
    hdrs = ["testing.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":dumper",
        ":packet_desc",
        "//flare/base:down_cast",
        "//flare/rpc/protocol:message",
    ],
)

cc_library(
    name = "dry_runner",
    srcs = ["dry_runner.cc"],
    hdrs = ["dry_runner.h"],
    visibility = ["//visibility:public"],
    deps = [
        ":packet_desc",
        "//flare/base:buffer",
        "//flare/base:dependency_registry",
        "//flare/base:expected",
        "//flare/base:future",
        "//flare/base:never_destroyed",
        "//flare/base:status",
        "//flare/base:string",
        "//flare/base/experimental:uuid",
        "//flare/base/net:endpoint",
        "//flare/fiber",
        "@com_github_gflags_gflags//:gflags",
    ],
)

cc_test(
    name = "dry_runner_test",
    srcs = ["dry_runner_test.cc"],
    deps = [
        ":dry_runner",
        "@com_github_gflags_gflags//:gflags",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_test(
    name = "dry_runner_integration_test",
    srcs = ["dry_runner_integration_test.cc"],
    deps = [
        ":binlog",
        "//flare/base:buffer",
        "//flare/base:deferred",
        "//flare/base:down_cast",
        "//flare/base:string",
        "//flare/base/crypto:blake3",
        "//flare/base/encoding:hex",
        "//flare/base/experimental:uuid",
        "//flare/base/internal:curl",
        "//flare/init:override_flag",
        "//flare/rpc",
        "//flare/rpc/binlog/util:proto_binlog_cc_proto",
        "//flare/rpc/binlog/util:proto_dry_runner",
        "//flare/rpc/protocol/protobuf:binlog_cc_proto",
        "//flare/rpc/protocol/protobuf:rpc_meta_cc_proto",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:endpoint",
        "//flare/testing:main",
        "@com_github_gflags_gflags//:gflags",
        "@com_github_jsoncpp//:jsoncpp",
    ],
)

cc_test(
    name = "dumper_integration_test",
    srcs = ["dumper_integration_test.cc"],
    deps = [
        ":binlog",
        "//flare/base:down_cast",
        "//flare/base:string",
        "//flare/init:override_flag",
        "//flare/rpc",
        "//flare/rpc/binlog/util:easy_dumping_log",
        "//flare/rpc/binlog/util:proto_binlog_cc_proto",
        "//flare/rpc/binlog/util:proto_dumper",
        "//flare/testing:echo_service_proto_flare",
        "//flare/testing:endpoint",
        "//flare/testing:main",
        "//flare/testing:relay_service_proto_flare",
        "@com_github_gflags_gflags//:gflags",
    ],
)
